//
// Created by work on 24-6-6.
//

#include "iot_model_device/CRtDeviceInfo.h"
#include "os/db/db.hpp"
#include "os/db/resultset.hpp"
#include <unordered_map>
#include "sw/redis++/redis.h"

namespace iotplat {
    std::map<CRtDeviceInfo::EDeviceCol, std::string> CRtDeviceInfo::rtDeviceColToStringMap = {
        {CRtDeviceInfo::EDeviceCol::EUser, "userid"},
        {CRtDeviceInfo::EDeviceCol::EName, "name"},
        {CRtDeviceInfo::EDeviceCol::EModelName, "model_name"},
        {CRtDeviceInfo::EDeviceCol::EDescr, "descr"},
        {CRtDeviceInfo::EDeviceCol::ESn, "sn"},
        {CRtDeviceInfo::EDeviceCol::EGroupIngs, "groupings"},
        {CRtDeviceInfo::EDeviceCol::EConfigs, "configs"},
        {CRtDeviceInfo::EDeviceCol::ELocation, "location"},
        {CRtDeviceInfo::EDeviceCol::ECreate_time, "create_time"},
        {CRtDeviceInfo::EDeviceCol::EProtocol, "protocol"},
        {CRtDeviceInfo::EDeviceCol::EFirmwareVersion, "firmware_version"},
        {CRtDeviceInfo::EDeviceCol::ELastOnlineTime, "last_online_time"},
        {CRtDeviceInfo::EDeviceCol::EAccruedOnlineTime, "accrued_online_time"},
        {CRtDeviceInfo::EDeviceCol::ESpecifications, "specifications"},
        {CRtDeviceInfo::EDeviceCol::EValid, "valid"},

        {CRtDeviceInfo::EDeviceCol::EPulse, "pulse"},
        {CRtDeviceInfo::EDeviceCol::ELoginTime, "login_time"},
        {CRtDeviceInfo::EDeviceCol::EOnlineState, "online_state"}
    };

    CRtDeviceInfo::CRtDeviceInfo() {
    }

    Json::Value CRtDeviceInfo::toJson() {
        Json::Value json;
        json[deviceFieldName(DEVICE_ENUM::EModelName)] = model_name;
        json[deviceFieldName(DEVICE_ENUM::EUser)] = user;
        json[deviceFieldName(DEVICE_ENUM::EName)] = name;
        json[deviceFieldName(DEVICE_ENUM::EDescr)] = descr;
        json[deviceFieldName(DEVICE_ENUM::ESn)] = sn;
        json[deviceFieldName(DEVICE_ENUM::ELocation)] = location;
        json[deviceFieldName(DEVICE_ENUM::EGroupIngs)] = grouping;
        json[deviceFieldName(DEVICE_ENUM::EConfigs)] = configs;
        json[deviceFieldName(DEVICE_ENUM::EProtocol)] = protocol;
        json[deviceFieldName(DEVICE_ENUM::EFirmwareVersion)] = firmware_version;
        json[deviceFieldName(DEVICE_ENUM::ELastOnlineTime)] = last_online_time.ToString();
        json[deviceFieldName(DEVICE_ENUM::ECreate_time)] = create_time.ToString();
        json[deviceFieldName(DEVICE_ENUM::EAccruedOnlineTime)] = accrued_online_time;
        json[deviceFieldName(DEVICE_ENUM::ESpecifications)] = specifications;
        json[deviceFieldName(DEVICE_ENUM::EValid)] = valid;
        json[deviceFieldName(DEVICE_ENUM::EPulse)] = pulse;
        json[deviceFieldName(DEVICE_ENUM::ELoginTime)] = login_time.ToString();
        json[deviceFieldName(DEVICE_ENUM::EOnlineState)] = online_state;
        return json;
    }

    void CRtDeviceInfo::fromJson(Json::Value json) {
    }
} // iotplat